using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


namespace LogAnalyzerIIS.LogClasses
{
	/// <summary>
	/// hits and hosts counter 
	/// </summary>
	public struct HitsNHosts
	{
		public HitsNHosts(int hits, int hosts)
		{
			Hits = hits;
			Hosts = hosts;
		}

		public int Hits;
		public int Hosts;
	}

	public class StatisticsPool
	{

		/// <summary>
		/// list of objects to count statistics
		/// </summary>
		public ArrayList StatList;

		/// <summary>
		/// total hits and hosts in all processed log files  
		/// </summary>
		public HitsNHosts TotalHitsNHosts = new HitsNHosts();

		/// <summary>
		/// list of unique IP addresses
		/// </summary>
		public List<string> UniqueIPs;

		/// <summary>
		/// list of entry pages and their hosts values
		/// </summary>
		public Dictionary<string, int> EntryPages;

		/// <summary>
		/// list of exit pages and their hosts values
		/// </summary>
		public Dictionary<string, int> ExitPages;

		/// <summary>
		/// list of browsers and their hits/hosts
		/// </summary>

		public Dictionary<string, HitsNHosts> Browsers;

		/// <summary>
		/// list of operating systems and their hits/hosts
		/// </summary>
		public Dictionary<string, HitsNHosts> OSes;

		/// <summary>
		/// actual minimal date of the records in the logs
		/// </summary>
		public DateTime MinDate = DateTime.MaxValue;

		/// <summary>
		/// actual maximal date of the records in the log
		/// </summary>
		public DateTime MaxDate = DateTime.MinValue;

		/// <summary>
		/// Initializes statistics pool
		/// </summary>
		public StatisticsPool()
		{
			UniqueIPs = new List<string>();
			EntryPages = new Dictionary<string, int>();
			ExitPages = new Dictionary<string, int>();
			Browsers = new Dictionary<string, HitsNHosts>();
			OSes = new Dictionary<string, HitsNHosts>();
			StatList = new ArrayList();
		}

		/// <summary>
		///   Clears all gathered statistics.
		/// </summary>
		public void Clear()
		{
			EntryPages.Clear();
			ExitPages.Clear();
			Browsers.Clear();
			OSes.Clear();
			UniqueIPs.Clear();
			TotalHitsNHosts.Hosts = 0;
			TotalHitsNHosts.Hits = 0;

			for (int i = 0; i < StatList.Count; i++)
			{
				if (StatList[i] is Dictionary<string, int>)
					(StatList[i] as Dictionary<string, int>).Clear();
				else
				{
					if (StatList[i] is Int64)
						StatList[i] = (Int64)0;
					else
					{
						if (StatList[i] is List<string>)
							(StatList[i] as List<string>).Clear();
					}
				}
			}
		}

		~StatisticsPool()
		{
			Clear();
		}
	}
}
